import babel from "@rollup/plugin-babel";
import glsl from "rollup-plugin-glsl";
import serve from "rollup-plugin-serve";
import livereload from "rollup-plugin-livereload";
import nodeResolve from "@rollup/plugin-node-resolve";

console.log(`现在处于 bundleless 状态`);

// Laya 打包使用的 Nodejs 为内部的低版本，使用我们的 Nodejs 打包即可
export default {
  input: "./src/Main.ts",
  output: [
    {
      file: `./bin/js/bundle.bundleless.js`,
      format: "es",
      paths: {
        // 必须使用这种方式精准匹配
        "game-random/src/random":
          "https://cdn.skypack.dev/game-random/dist/random"
      }
    }
  ],
  plugins: [
    babel({
      presets: ["@babel/typescript"],
      extensions: [".ts"],
      babelHelpers: "bundled",
      exclude: ["node_modules"],
      plugins: [
        // 添加对装饰器的解析
        ["@babel/plugin-proposal-decorators", { legacy: true }],
        ["@babel/plugin-proposal-class-properties", { loose: true }],
        [
          "module-resolver",
          {
            alias: {
              source: "./source"
            }
          }
        ]
      ]
    }),
    nodeResolve({ extensions: [".js", ".ts"], moduleDirectories: [] }),
    glsl({
      // By default, everything gets included
      include: /.*(.glsl|.vs|.fs)$/,
      sourceMap: false,
      compress: false
    }),

    serve({
      open: true,
      openPage: `/bundleless.html`,
      contentBase: "./bin",
      host: "localhost",
      port: 10001
    }),
    livereload({ watch: ["src", "source", "bin", "laya"] })
  ]
};
